package com.ponhu.ea2.vo;

import com.ponhu.ea2.enums.InventoryAppraisalEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author Wang
 * @date 2021/12/10 5:48 下午
 */
@ApiModel("选品详情数据")
@Data
@Accessors(chain = true)
public class PickInventoryDetailVo extends PickInventoryVo implements Serializable {
    private static final long serialVersionUID = -8350929682742607364L;

    @ApiModelProperty(value = "鉴定师")
    private String appraiserName;

    @ApiModelProperty(value = "原产地")
    private String provenance;

    @ApiModelProperty(value = "瑕疵")
    private String flaw;

    @ApiModelProperty(value = "备注")
    private String remarks;

    @ApiModelProperty(value = "中检状态说明")
    private String ccicStatusStr;

    @ApiModelProperty("卖点")
    private String sellingPoint;

    @ApiModelProperty(value = "检测备注")
    private String maintainRemarks;

    @ApiModelProperty(value = "检测结果")
    private String maintainResult;

    @ApiModelProperty(value = "货品相关物料详情")
    private PhMaterialVo phMaterialVo;

    @ApiModelProperty(value = "货品属性：货品详情使用")
    private List<PhPropertyVo> phPropertList;

    @ApiModelProperty(value = "货品附件集合")
    private List<PhInventoryAccessoryVo> annexList;

    @ApiModelProperty(value = "货品配件集合")
    private List<PhInventoryAccessoryVo> accessoryList;

    @ApiModelProperty(value = "在库时长")
    private Integer warehouseAliveDay;

    @ApiModelProperty(value = "采购数据")
    private PickInventoryPurchaseVo pickInventoryPurchaseVo;

    public String getCcicStatusStr() {
        Optional<String> optional = Arrays.stream(InventoryAppraisalEnum.values())
                .filter(aEnum -> aEnum.getCode().equals(super.getCcicStatus()))
                .map(InventoryAppraisalEnum::getName).findFirst();
        return optional.orElse(null);
    }

    public String getCategoryName() {
        if (ObjectUtils.isEmpty(phMaterialVo)) return super.getCategoryName();
        return Arrays.asList(phMaterialVo.getFirstCategoryName(),
                        phMaterialVo.getSecondCategoryName(), phMaterialVo.getThirdCategoryName())
                .stream().filter(StringUtils::isNotEmpty).collect(Collectors.joining("-"));
    }

}
